/*
 * ZBrowser is an embeddable browser component.
 * Copyright (C) Author: Gangadhar Nagesh Metla (Novell, Inc.)
 * nmetla74@gmail.com 
 * Version 1.0
 * 1/3/2009
 * Filename ZURLConnection.java
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package com.novell.zenworks.agent.zbrowser;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class ZURLConnection extends URLConnection
{

    InputStream in;

    ZURLConnection(URL u, InputStream in)
    {

        super(u);

        this.in = in;

        this.setDoInput(true);
        this.setDoOutput(true);

    }

    public void connect()
    {

        return;

    }

    public InputStream getInputStream() throws IOException
    {
    	return in;
    }

    public String getContentType()
    {
        String type = guessContentTypeFromName(".html");
        return type;
    }

    public Object getContent() throws IOException
    {

        String retval = null;

        int nbytes;

        byte buf[] = new byte[1024];

        try
        {

            while ((nbytes = in.read(buf, 0, 1024)) != -1)
            {

                retval += new String(buf, 0, 0, nbytes);

            }

        } catch (Exception e)
        {
            throw new IOException("ZURLConnection::getContent: Exception\n" + e);
        }

        return retval;

    }

    public void disconnect()
    {
        this.disconnect();
    }

}